'use strict'

const xtpl = require( 'xtpl' );
const orm = require( 'orm' );

// 获取视频列表页面
exports.getVideoListPage = ( req, res ) => {
  const keyword = req.query.keyword || '';
  req.models.video.find( {
    vtitle: orm.like( '%' + keyword + '%' )
  }, {
    offset: 0,
    limit: 3
  }, ( err, videos ) => {
    xtpl.renderFile( './views/videolist.html', {
      uname: req.session.uname,
      list: videos,
      keyword: keyword
    }, ( err, content ) => {
      if ( err ) {
        console.log( err );
        return;
      }
      res.setHeader( 'Content-Type', 'text/html;charset=utf8' );
      res.end( content );
    } );
  } );
};
